package dl.transactionscript.service;

import java.sql.ResultSet;
import java.sql.SQLException;

import dl.common.service.iface.ProductServiceInterface;
import dl.exception.handler.ApplicationException;
import dl.transactionscript.gateway.TableDataGateway;

public class ProductService implements ProductServiceInterface{

	private TableDataGateway tableDataGateway;

	public ProductService() {
		tableDataGateway = new TableDataGateway();
	}

	public long insertProductInformation(String productName, String productType)
			throws ApplicationException {
		long newProductId = 0;
		try {
			newProductId = tableDataGateway.insertProduct(productName,
					productType);
		} catch (SQLException e) {
			throw new ApplicationException(e);
		}
		return newProductId;
	}

	public void deleteProductInformation(long id) throws ApplicationException {
		try {
			tableDataGateway.deleteProduct(id);
		} catch (SQLException e) {
			throw new ApplicationException(e);
		}
	}

	public void showProductList() throws ApplicationException {
		try {
			ResultSet rs = tableDataGateway.findProductAll();
			System.out.println("Product : ");
			while (rs.next()) {
				System.out.println(rs.getInt(1) + ":" + rs.getString(2) + ":"
						+ rs.getString(3));
			}
		} catch (SQLException e) {
			throw new ApplicationException(e);
		}
	}

}
